package lecture09.studentWork;

class Student {
    private String name;
    private String ID;
    private double[] score;

    public Student(String name, String ID) {
        this.name = name;
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }
    public boolean setScore(double[] fenshu) {
        this.score = new double[3];
        for (int i = 0; i < fenshu.length; i++) {
            if (fenshu[i] < 0 || fenshu[i] > 100) {
                return false;
            }this.score[i] = fenshu[i];
        }
        return true;
    }

    public double[] getScore() {
        return score;
    }
    public double sum() {
        double total = 0;
        for (double v : score) {
            total += v;
        }
        return total;
    }
    public double average() {
        return sum() / score.length;
    }
    public double[] max_min() {
        double max = score[0];
        double min = score[0];
        for (double v : score) {
            if (v > max) {
                max = v;
            }
            if (v < min) {
                min = v;
            }
        }
        return new double[]{max, min};
    }
    public void printInf() {
        double total = sum();
        double avg = average();
        double[] maxMin = max_min();
        System.out.println("***学生成绩查询系统***");
        System.out.println("姓名："+name+" "+"学号："+ID);
        System.out.println("总分："+total);
        System.out.println("平均分："+avg);
        System.out.println("最高分："+maxMin[0]);
        System.out.println("最低分："+maxMin[1]);
        System.out.println("********************");
    }

}




public class TestStudent {
    static void main() {
        Student s1 = new Student("LiNan", "23222200000");
        double[] score = {90, 100, 60};
        if (s1.setScore(score)) {
            s1.printInf();
        }else {
            System.out.println("分数输入不合法");
        }

        Student s2 = new Student("LiNan111", "23222200001");
        double[] score1 = {-10, 100, 60};
        if (s2.setScore(score1)) {
            s2.printInf();
        }else {
            System.out.println("分数输入不合法");
        }
    }
}
